package edu.npu.GraphTransform;

import java.io.IOException;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;

public class GraphSlim {
	private static final String SEPARATOR = "\t";
	
	public static class GraphSlimMapper extends Mapper<LongWritable, Text, Text, Text> {
		@Override
		protected void map(LongWritable key, Text value, Context context)
				throws IOException, InterruptedException {
			String line = value.toString();
			String[] splits = line.split(SEPARATOR);
			if(Long.parseLong(splits[1]) < Long.parseLong(splits[2]))
				context.write(new Text(value), new Text(""));
			else
				context.write(new Text(splits[0] + SEPARATOR + splits[2] + SEPARATOR + splits[1]), new Text(""));
		}
	}
	public static class GraphSlimReducer extends Reducer<Text, Text, Text, Text> {
		@Override
		protected void reduce(Text key, Iterable<Text> values, Context context)
				throws IOException, InterruptedException {
				context.write(key, null);
		}
	}
}
